<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客系统</title>
    <link rel="stylesheet" href="common.css">
    <link rel="stylesheet" href="blog.list.css">
</head>
<body>

    <div class="nav">
        <img src="./img/3.png" alt="">
        <span>我的博客系统</span>
        <div class="spacer"></div>
        <a href="blog.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout89">注销</a>
    </div>
    <div class="container">
        <div class="container-left">
            <!-- 用户的信息 -->
            <div class="card">
                <!-- 头像 -->
                <img src="./img/2.png" alt="">
                <!-- 名字 -->
                <h3></h3>
                <a href="#">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>3</span>
                    <span>2</span>
                </div>
            </div>
        </div>
        <div class="container-right">
            <!-- 每个.blog来表示一篇文章
            <div class="blog">
                <div class="title">我的第一篇博客</div>
                <div class="date">2022-11-06 12:00:00</div>
                <div class="desc">
                    要好好学习
                </div>
                <a href="blog_detail.html">查看全文 &gt;&gt;</a>
            </div> -->
        </div>
    </div>
    <script src="js/app.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
        <script>
            function getBlogs(){
            $.ajax({
                type:'get',
                url:'blog',
                success:function (body){
                    let container=document.querySelector('.container-right');
                    for(let blog of body){
                        let blogDiv=document.createElement('div')
                        blogDiv.className='blog';
                        let titleDiv=document.createElement('div');
                        //标题
                        titleDiv.className='title';
                        titleDiv.innerHTML=blog.title;
                        //日期
                        let dateDiv = document.createElement('div');
                        dateDiv.className= 'date';
                        dateDiv.innerHTML= blog.postTime;

                        //摘要
                        let descDiv=document.createElement('div');
                        descDiv.className= 'desc' ;
                        descDiv.innerHTML= blog.content ;

                        //构造全文按钮
                        let a=document.createElement('a');
                        a.href= 'blog_detail.html?blogId=' + blog.blogId;
                        a.innerHTML= '查看全文 &gt;&gt;';
                        //封装
                        blogDiv.appendChild(titleDiv);
                        blogDiv.appendChild(dateDiv);
                        blogDiv.appendChild(descDiv);
                        blogDiv.appendChild(a);
                        container.appendChild(blogDiv);
                    }
                }
            })
        }
        getBlogs();
        getLoginStatus();
        //针对博客列表页，来获取当前用户信息
        function getUserInfo(){
            $.ajax({
                type:'get',
                url:'userInfo',
                success:function(body){
                    //把获取到的信息填写到用户表上
                    let h3=document.querySelector('.container-left>.card>h3');
                    h3.innerHTML = body.username;
                }
            })
        }
        getUserInfo();
        </script>
</body>
</html>